﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace ERPTemplate.administrator
{
    public partial class CreateCompany : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_create_Click(object sender, EventArgs e)
        {
            if (valid())
            {
                RuleCode.Table.Company c = new RuleCode.Table.Company();
                c.New();
                c.CompanyID.Value = TextBox1.Text;
                c.Name.Value = TextBox2.Text;
                c.Insert();
                //RuleCode.CurrentUtil.CompanyID = c.CompanyID.Value;
                RuleCode.Table.User u = new RuleCode.Table.User();
                u.Userid.Value = "admin";
                u.Name.Value = "admin";
                u.Password.Value = TextBox3.Text.Trim();
                u.Insert();
                //RuleCode.Table.User.login(
                //this.TextBox1.Text.Trim(),
                //this.TextBox2.Text.Trim(),
                //this.TextBox3.Text.Trim());
                Response.Redirect("/Default.aspx");

            }
        }
        private bool valid()
        {
            RuleCode.Table.Company c = RuleCode.Table.Company.Find(" CompanyID = '"
                + TextBox1.Text.Trim() + "' ");
            if (c.Count > 0)
            {
                MessageBox.Show(this.Page, "公司名称已存在");
                return false;
            }
            if (TextBox3.Text.Trim() != TextBox4.Text.Trim())
            {
                MessageBox.Show(this.Page, "两次输入的密码不一样");
                return false;
            }
            return true;

        }
    }
}
